/*
	Colored Trails
	
	Copyright (C) 2006, President and Fellows of Harvard College.  All Rights Reserved.
	
	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

package ctgui.original;

import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * A dialog to allow a user to connect to a given server.
 *
 * @author Paul Heymann (ct3@heymann.be)
 */
public class ConnectDialog extends JFrame {
    private JPanel connectPanel;
    private JButton cancelButton;
    private JButton connectButton;
    private JTextField connectToTextField;

    public ConnectDialog() {

        setTitle("Name: " + GUI.getAgent().getClientName() + " Connect to...");

        setContentPane(connectPanel);
        setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
        connectButton.requestFocus();
        connectButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String hostip = connectToTextField.getText();
                Taskbar.getInstance().getAgent().setServerHostname(hostip);
                GUI.connectAndWait();
                setVisible(false);
            }
        });
        cancelButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                setVisible(false);
            }
        });
        pack();
    }

    {
// GUI initializer generated by IntelliJ IDEA GUI Designer
// !!! IMPORTANT !!!
// DO NOT EDIT OR ADD ANY CODE HERE!
        $$$setupUI$$$();
    }

    /**
     * Method generated by IntelliJ IDEA GUI Designer
     * !!! IMPORTANT !!!
     * DO NOT edit this method OR call it in your code!
     */
    private void $$$setupUI$$$() {
        connectPanel = new JPanel();
        connectPanel.setLayout(new GridLayoutManager(2, 1, new Insets(5,
                5, 5, 5), -1,
                -1));
        final JPanel panel1 = new JPanel();
        panel1.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0,
                0), -1,
                -1));
        connectPanel.add(panel1,
                new GridConstraints(0, 0, 1, 1,
                        GridConstraints.ANCHOR_CENTER,
                        GridConstraints.FILL_BOTH,
                        GridConstraints.SIZEPOLICY_CAN_SHRINK |
                GridConstraints.SIZEPOLICY_CAN_GROW,
                        GridConstraints.SIZEPOLICY_CAN_SHRINK |
                GridConstraints.SIZEPOLICY_CAN_GROW,
                        null, null, null));
        final JLabel label1 = new JLabel();
        label1.setText(" Server to Connect To:");
        panel1.add(label1,
                new GridConstraints(0, 0, 1, 1,
                        GridConstraints.ANCHOR_WEST,
                        GridConstraints.FILL_NONE,
                        GridConstraints.SIZEPOLICY_FIXED,
                        GridConstraints.SIZEPOLICY_FIXED, null, null,
                        null));
        connectToTextField = new JTextField();
        connectToTextField.setText("localhost");
        panel1.add(connectToTextField,
                new GridConstraints(0, 1, 1, 1,
                        GridConstraints.ANCHOR_WEST,
                        GridConstraints.FILL_HORIZONTAL,
                        GridConstraints.SIZEPOLICY_WANT_GROW,
                        GridConstraints.SIZEPOLICY_FIXED, null,
                        new Dimension(150, -1), null));
        final JPanel panel2 = new JPanel();
        panel2.setLayout(new GridLayoutManager(1, 3, new Insets(0, 0, 0,
                0), -1,
                -1));
        connectPanel.add(panel2,
                new GridConstraints(1, 0, 1, 1,
                        GridConstraints.ANCHOR_CENTER,
                        GridConstraints.FILL_BOTH,
                        GridConstraints.SIZEPOLICY_CAN_SHRINK |
                GridConstraints.SIZEPOLICY_CAN_GROW,
                        GridConstraints.SIZEPOLICY_CAN_SHRINK |
                GridConstraints.SIZEPOLICY_CAN_GROW,
                        null, null, null));
        connectButton = new JButton();
        connectButton.setSelected(true);
        connectButton.setText("Connect");
        connectButton.setToolTipText("Connect to Remote Server");
        panel2.add(connectButton,
                new GridConstraints(0, 1, 1, 1,
                        GridConstraints.ANCHOR_CENTER,
                        GridConstraints.FILL_HORIZONTAL,
                        GridConstraints.SIZEPOLICY_CAN_SHRINK |
                GridConstraints.SIZEPOLICY_CAN_GROW,
                        GridConstraints.SIZEPOLICY_FIXED, null, null,
                        null));
        cancelButton = new JButton();
        cancelButton.setText("Cancel");
        cancelButton.setToolTipText("Cancel Connection Attempt");
        panel2.add(cancelButton,
                new GridConstraints(0, 2, 1, 1,
                        GridConstraints.ANCHOR_CENTER,
                        GridConstraints.FILL_HORIZONTAL,
                        GridConstraints.SIZEPOLICY_CAN_SHRINK |
                GridConstraints.SIZEPOLICY_CAN_GROW,
                        GridConstraints.SIZEPOLICY_FIXED, null, null,
                        null));
        final Spacer spacer1 = new Spacer();
        panel2.add(spacer1,
                new GridConstraints(0, 0, 1, 1,
                        GridConstraints.ANCHOR_CENTER,
                        GridConstraints.FILL_HORIZONTAL,
                        GridConstraints.SIZEPOLICY_WANT_GROW, 1, null,
                        null, null));
    }
}
